<template>
    <web-view :src="src"></web-view>
</template>

<script>
import { mapGetters } from 'vuex'
import { getBasicUser } from '@/utils/auth'

export default {
	data() {
		return {
			src: '',
			options: {},
			roleName: ''
		}
	},
	computed: {
		...mapGetters({ userInfo: 'getBasicUser' })
	},
	onLoad(options) {
		this.options = options
		if (options.user_id) {
			getBasicUser(options.user_id).then(res => {
				if (res.role_id) {
					if (res.role_id == 1 || res.role_id == 2) {
						this.roleName = ''
					} else {
						this.roleName = '的名片'
					}
				}
				this.roleName = ''
			})
		}
		if (options.returnUrl) {
			this.src = decodeURIComponent(options.returnUrl)
		} else if (options.role_id) {
			let path = ''
			if (options.role_id == 1) {
				path = 'company'
			}

			if (options.role_id == 2) {
				path = 'material'
			}

			if (options.role_id > 2) {
				path = 'person'
			}
			this.src = this.$constant.formal + '/hkds/#/' + path + '?type=hkds_miniapp&owner_user_id=' + uni.getStorageSync('user_id') + '&token=' + uni.getStorageSync('token')
		} else {
			this.src = this.$constant.formal + '/hkds/#/company?type=hkds_miniapp&owner_user_id=' + uni.getStorageSync('user_id') + '&token=' + uni.getStorageSync('token')
		}
	},
	/**
     * 用户点击右上角分享
     */
	onShareAppMessage: function(options) {
		let shareObj = {}
		// C端页面上线使用，后期删除
		let isCompanyIndex = options.webViewUrl ? options.webViewUrl.indexOf('#/company?') : -1
		let isPersonIndex = options.webViewUrl ? options.webViewUrl.indexOf('#/person?') : -1
		let isMaterialIndex = options.webViewUrl ? options.webViewUrl.indexOf('#/material?') : -1

		let isBaoJia = options.webViewUrl ? options.webViewUrl.indexOf('/prebook/price?') : -1
		let isSheJi = options.webViewUrl ? options.webViewUrl.indexOf('/prebook/huxing?') : -1
		// let isQiYe = options.webViewUrl ? options.webViewUrl.indexOf('/enterpricse/index?') : -1
		// let isLianMeng = options.webViewUrl ? options.webViewUrl.indexOf('/team?') : -1
		let isFengShui = options.webViewUrl ? options.webViewUrl.indexOf('prebook/fengshui?') : -1
		let isAnLi = options.webViewUrl ? options.webViewUrl.indexOf('/case/detail?') : -1
		let isWenZhang = options.webViewUrl ? options.webViewUrl.indexOf('/article/detail?') : -1
		let isHuoDong = options.webViewUrl ? options.webViewUrl.indexOf('/promotion/detail?') : -1

		let params = options.webViewUrl ? options.webViewUrl.split('?')[1] : `owner_user_id=${this.userInfo.user_id}`

		if (isCompanyIndex > 0) {
			shareObj = {
				title: this.userInfo.nick_name + this.userInfo.role_name,
				path: `/pages/design/designCompany/indexNew?${params}`
			}
		} else if (isPersonIndex > 0) {
			shareObj = {
				title: this.userInfo.nick_name + this.userInfo.role_name,
				path: `/pages/design/designerIndex?${params}`
			}
		} else if (isMaterialIndex > 0) {
			options.webViewUrl = options.webViewUrl.replace(/token/g, 'null')
			shareObj = {
				title: this.userInfo.nick_name + this.userInfo.role_name,
				path: `/pages/page/webview/index?user_id=${this.userInfo.user_id}&returnUrl=${encodeURIComponent(options.webViewUrl)}`
			}
		} else if (isBaoJia > 0) {
			shareObj = {
				title: '5秒免费获取你家的装修报价，快戳进来算一下吧【' + this.userInfo.nick_name + '】',
				path: `/pages/pagesHome/thematicmo/inteoffer?${params}`
			}
		} else if (isSheJi > 0) {
			shareObj = {
				title: '0元享专业全屋设计【' + this.userInfo.nick_name + '】',
				path: `/pages/pagesHome/active/houseDesign?${params}`
			}
		} else if (isFengShui > 0) {
			shareObj = {
				title: '快来测下你家的风水【' + this.userInfo.nick_name + '】',
				path: `/pages/pagesHome/shop/ShopDivination?${params}`
			}
		} else if (isAnLi > 0) {
			shareObj = {
				title: this.userInfo.nick_name + this.userInfo.role_name,
				path: `/pages/case/casedetail?${params}`
			}
		} else if (isWenZhang > 0) {
			shareObj = {
				title: this.userInfo.nick_name + this.userInfo.role_name,
				path: `/pages/getGuest/articledetail?${params}`
			}
		} else if (isHuoDong > 0) {
			shareObj = {
				title: this.userInfo.nick_name + this.userInfo.role_name,
				path: `/pages/pagesHome/promotion/detail?${params}`
			}
		} else {
			if (this.userInfo.role_id == 1) {
				shareObj = {
					title: this.userInfo.nick_name + this.userInfo.role_name,
					path: `/pages/design/designCompany/indexNew?${params}`
				}
			} else if (this.userInfo.role_id > 2) {
				shareObj = {
					title: this.userInfo.nick_name + this.userInfo.role_name,
					path: `/pages/design/designerIndex?${params}`
				}
			} else {
				options.webViewUrl = options.webViewUrl.replace(/token/g, 'null')
				options.webViewUrl = options.webViewUrl.replace(/isSelf/g, 'null')
				shareObj = {
					title: this.userInfo.nick_name + this.userInfo.role_name,
					path: `/pages/page/webview/index?user_id=${this.userInfo.user_id}&returnUrl=${encodeURIComponent(options.webViewUrl)}`
				}
			}
		}
		return shareObj
	}
}
</script>

<style lang="scss" scoped>
</style>
